package com.sunyur.tailor.channel.common.middle.util;

import com.sunyur.tailor.channel.common.middle.base.ChannelDataResult;
import com.sunyur.tailor.channel.common.middle.enums.MiddleResultEnum;

/**
 *
 * @Description:返回工具类
 */
public class ChannelDataResultUtil {

    private ChannelDataResultUtil() {
    }

    /** *
     * @Description: 生成成功实体对象
     */
    public static final <H,I> ChannelDataResult<H,I> success(H head,I item){
        ChannelDataResult<H,I> result = new ChannelDataResult<>();
        result.setCode(MiddleResultEnum.SUCCESS.getCode());
        result.setHead(head);
        result.setItem(item);
        return result;
    }

    /** *
     * @Description: 生成错误实体对象
     */
    public static final <H,I> ChannelDataResult<H,I> error(String code, String message){
        ChannelDataResult<H,I> result = new ChannelDataResult<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    /**
     * @Description: 判断是否成功
     */
    public static <H,I> boolean isSuccess(ChannelDataResult<H,I> channelDataResult) {
        if (channelDataResult != null && channelDataResult.getCode().equals(MiddleResultEnum.SUCCESS.getCode()) && channelDataResult.getHead() != null&& channelDataResult.getItem() != null) {
            return true;
        }
        return false;
    }
}
